<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of product_image_model
 *
 * @author Administrator
 */
class product_image_model extends CI_Model {

    //put your code here
    function __construct() {
        parent::__construct();
    }

    function getImagesDefaultByProduct($product_id) {
        $arr = array
            ('product_id' => $product_id,
            'image_is_delete' => 0,
            'image_display_state' => 1,
            'image_is_default' => 1
        );
        $query = $this->db->get_where(tbl_product_images, $arr);
        $rs = $query->result();
        $count = $query->num_rows();
        if ($count <= 0)
            return null;
        return $rs[0];
    }

    function getImagesByProduct($product_id) {
        $arr = array(
            'product_id' => $product_id,
            'image_is_delete' => 0,
            'image_display_state' => 1,
            'image_is_default' => 0
        );
        $query = $this->db->get_where(tbl_product_images, $arr);
        return $query->result();
    }

    function getImagesByProduct1($product_id) {
        $arr = array(
            'product_id' => $product_id,
            'image_is_delete' => 0,
            'image_display_state' => 1
        );
        $query = $this->db->get_where(tbl_product_images, $arr);
        return $query->result();
    }

    function addImage($info) {
        return $this->db->insert(tbl_product_images, $info);
    }

    function deleteImage($id){
        $this->db->where('image_id',$id);
        return $this->db->update(tbl_product_images,array('image_is_delete'=>1));
    }
}

?>
